<?php
/**
 * Description: 批量代付模型
 * User: wuhao
 * Date: 2017-07-03
 * Time: 11:11
 */
namespace app\backend\model;
use think\Model;

class BatchPayment extends Model
{
    private $_batchPayment = 'z_batch_payment';

    /**
     * 新增批量代付的记录(目前只记录通联支付的)
     * @param  array $data    新增的纪录
     * @return mixed
     */
    public function addRecord(array $data)
    {
        if (!$data || !is_array($data)) {
            return false;
        }

        $insertData = [];
        foreach ($data as $v) {
            $insertData[] = [
                'mid'         => $v['mid'],
                'payer_id'    => $v['payer_id'],
                'ordernum'    => $v['ordernum'],
                'begin_cycle' => $v['begin_cycle'],
                'end_cycle'   => $v['end_cycle'],
                'money'       => $v['money'],
                'service_money' => $v['service_money'],
                'actual_money' => $v['actual_money'],
                'pay_time'    => date('Ymd'),
                'update_time' => time(),
                'req_sn'      => '',
                'status'      => 0
            ];
        }
        $res = $this->table($this->_batchPayment)->insertAll($insertData);
        return $res;
    }

    /**
     * 更新数据
     * @param $where 条件
     * @param $data  内容
     * @return mixed
     */
    public function updateData($where, $data)
    {
        return $this->table($this->_batchPayment)->where($where)->update($data);
    }

    /**
     * @comment  获取批量代付列表
     * @author wuhao
     * @param $where
     * @param string $field
     * @return mixed
     */
    public function getList($where, $field = '*')
    {
        return $this->table($this->_batchPayment)->field($field)->where($where)->select();
    }
}